<template>
    <div class="container-content">
        <el-form
            ref="elForm"
            :model="formData"
            :rules="rules"
            size="medium"
            label-width="100px"
        >
            <el-form-item label-width="200px" label="项目Id" prop="projectId">
                <el-input
                    v-model="formData.projectId"
                    placeholder="请输入项目Id"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item label-width="200px" label="仓库编码" prop="wareCode">
                <el-input
                    v-model="formData.wareCode"
                    placeholder="请输入仓库编码"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="关联部门"
                prop="relationId"
            >
                <el-select
                    v-model="formData.relationId"
                    placeholder="请选择关联部门"
                    clearable
                    :style="{ width: '100%' }"
                >
                    <el-option
                        v-for="(item, index) in relationIdOptions"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label-width="200px" label="名称" prop="title">
                <el-input
                    v-model="formData.title"
                    placeholder="请输入名称"
                    clearable
                    :style="{ width: '100%' }"
                ></el-input>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="库管Id"
                prop="wareManagement"
            >
                <el-input
                    v-model="formData.wareManagement"
                    placeholder="请输入库管Id"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item label-width="200px" label="仓库名称" prop="wareName">
                <el-input
                    v-model="formData.wareName"
                    placeholder="请输入仓库名称"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import { add } from "@/api/base/data";
import { updataWarehouseList,editWarehouseList } from "@/api/bim/outher";
export default {
    components: {},
     props: ["id"],
    data() {
        return {
            flag:false,
            formData: {
                projectId: undefined,
                wareCode: undefined,
                relationId: undefined,
                title: undefined,
                wareManagement: undefined,
                wareName: undefined,
            },
            rules: {
                projectId: [
                    {
                        required: true,
                        message: "请输入项目Id",
                        trigger: "blur",
                    },
                ],
                wareCode: [
                    {
                        required: true,
                        message: "请输入仓库编码",
                        trigger: "blur",
                    },
                ],
                relationId: [
                    {
                        required: true,
                        message: "请选择关联部门",
                        trigger: "change",
                    },
                ],
                title: [
                    {
                        required: true,
                        message: "请输入名称",
                        trigger: "blur",
                    },
                ],
                wareManagement: [
                    {
                        required: true,
                        message: "请输入库管Id",
                        trigger: "blur",
                    },
                ],
                wareName: [
                    {
                        required: true,
                        message: "请输入仓库名称",
                        trigger: "blur",
                    },
                ],
            },
            relationIdOptions: [
                {
                    label: "创建",
                    value: 1,
                },
                {
                    label: "审核中",
                    value: 2,
                },
                {
                    label: "已审核",
                    value: 3,
                },
            ],
        };
    },
    computed: {},
    watch: {},
    created() {},
    mounted() {
        if (this.id!='') {
            updataWarehouseList(this.id).then((res=>{
                this.formData=res.data
                this.flag=true
            }))
        }
    },
    methods: {
        submitForm(cb) {
          if (this.flag) {
              this.$refs["elForm"].validate((valid) => {
                if (!valid) return;
                // TODO 提交表单
                editWarehouseList(this.formData, "Warehouse").then((res) => {
                    if (res.code === 200) {
                        cb();
                        this.$message.success("修改成功");
                        this.flag=false
                    }
                });
            });
          }else{
              this.$refs["elForm"].validate((valid) => {
                if (!valid) return;
                // TODO 提交表单
                add(this.formData, "Warehouse").then((res) => {
                    if (res.code === 200) {
                        cb();
                        this.$message.success("新增成功");
                    }
                });
            });
          }
        },
        resetForm() {
            this.$refs["elForm"].resetFields();
        },
    },
};
</script>
<style></style>
